package org.e_gold.dao.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.e_gold.dao.CEventDAO;
import org.e_gold.model.crawler.livescore.CEvent;
import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author Thang Nguyen
 */
@Repository
public class CEventDAOImpl extends AbstractGenericDAO<CEvent> implements CEventDAO {

	@SuppressWarnings("unused")
	private static final Logger logger = Logger.getLogger(CEventDAOImpl.class);

	public CEventDAOImpl() {
		super(CEvent.class);

	}

	@SuppressWarnings("unchecked")
	@Override
	@Transactional(readOnly = true)
	public List<CEvent> getCEventInRange(Date dFrom, Date dTo) {
		Criteria crit = getCurrentSession().createCriteria(CEvent.class);
		crit.add(Restrictions.between("play_date", dFrom, dTo));

		List<CEvent> data = crit.list();
		List<CEvent> retList = new ArrayList<CEvent>();
		for(CEvent ce : data){
			retList.add(ce);
		}
		return retList;
	}
}
